package com.tianyadu.order.utils.stream;

import com.tianyadu.order.dto.OrderDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Component;

/**
 * @FileName: StreamReceiver
 * @Description: 消息接收端
 * @author: xueyj
 * @create: 2018-11-26 06:16
 */
@Component
@EnableBinding(StreamClient.class)
@Slf4j
public class StreamReceiver {

    /**
     * 接收orderDTO对象 消息
     * @param message
     */
    /**
      * @Description: 接收orderDTO对象 消息，并反馈信息至消息发送者（需要使用消息发送者的消息名称）
      * @StreamListener(value = StreamClient.INPUT)-->监听消息队列
      * @SendTo(StreamClient.INPUT2) --> 发送消息（反馈结果）至目标
      * @param:
      * @return:
      * @author:
      * @date:   2018/11/26 6:47
      */
    @StreamListener(value = StreamClient.INPUT)
    @SendTo(StreamClient.INPUT2)
    public String process(OrderDTO message) {
        log.info("StreamReceiver: {}", message);
        return "received.";
    }

    /**
      * @Description: 模拟接收反馈结果信息
      * @param:
      * @return:
      * @author:
      * @date:   2018/11/26 6:50
      */
    @StreamListener(value = StreamClient.INPUT2)
    public void process2(String message) {
        log.info("StreamReceiver2: {}", message);
    }
}